package com.yu.controller;

import com.yu.pojo.Dept;
import com.yu.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping
    public String findAllDept(){
        String result = deptService.findAllDept();
        return result;
    }

    @DeleteMapping("/{id}")
    public String removeDept(@PathVariable("id") Integer id){
        String result = deptService.removeById(id);
        return result;
    }

    @PostMapping
    public String addDept(@RequestBody Dept dept){
        String result = deptService.addDept(dept);
        return result;
    }

    @GetMapping("/{id}")
    public String findDeptById(@PathVariable("id") Integer id){
        String result = deptService.findByIdDept(id);
        return result;
    }

    @PutMapping
    public String updateDept(@RequestBody Dept dept){
        String result = deptService.updateDept(dept);
        return result;
    }
}
